Skip to content

fix incorrect suggestions in private import diagnostic#156244

Merged
rust-bors[bot] merged 6 commits intorust-lang:mainfrom
el-ev:issue156060
May 8, 2026
Merged

fix incorrect suggestions in private import diagnostic#156244
rust-bors[bot] merged 6 commits intorust-lang:mainfrom
el-ev:issue156060

Conversation

@el-ev
Copy link
Copy Markdown
Contributor

@el-ev el-ev commented May 6, 2026

View all comments

Resolves #156060.

  1. In nested imports like use two::{One, ...}, the diagnostic suggested replacing the One with a multi-segment path of a different module, producing invalid code like use crate::two::{one::One, Two}. Skip it when single_nested == true.
  2. Stop unconditionally skipping the first segment of import.module_path, which can produce incorrect paths in edition 2018 and later.
  3. Mark the suggestion as "directly" instead of "through the re-export" when the import's source is the definition itself.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 6, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 6, 2026

r? @jdonszelmann

rustbot has assigned @jdonszelmann.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 19 candidates

Copy link
Copy Markdown
Member

@mu001999 mu001999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, the following will also emit an invalid suggestion (invalid after edition 2015), because we skipped the first segment:

mod one {
    pub struct One;
}

mod two {
    use crate::one::One;
}

mod test {
    use crate::two::One;
}

View changes since this review

Comment thread compiler/rustc_resolve/src/diagnostics.rs Outdated
@el-ev el-ev changed the title skip incorrect suggestion in nested imports fix incorrect suggestions in private import diagnostic May 7, 2026
@el-ev el-ev requested a review from mu001999 May 7, 2026 15:58
@rust-log-analyzer

This comment has been minimized.

@el-ev
Copy link
Copy Markdown
Contributor Author

el-ev commented May 7, 2026

I'll take a look later this day

Comment thread compiler/rustc_resolve/src/diagnostics.rs
Comment thread compiler/rustc_resolve/src/diagnostics.rs Outdated
Comment thread compiler/rustc_resolve/src/diagnostics.rs Outdated
Co-Authored-By: mu001999 <mu001999@outlook.com>
@rust-log-analyzer

This comment has been minimized.

Comment thread tests/ui/imports/private-import-no-suggestion-156244.stderr Outdated
Comment thread tests/ui/imports/private-import-nested-suggestion-156060.rs
@mu001999
Copy link
Copy Markdown
Member

mu001999 commented May 8, 2026

r? me

@rustbot rustbot assigned mu001999 and unassigned jdonszelmann May 8, 2026
Copy link
Copy Markdown
Member

@mu001999 mu001999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 8, 2026

📌 Commit 6d5fc32 has been approved by mu001999

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 8, 2026
rust-bors Bot pushed a commit that referenced this pull request May 8, 2026
Rollup of 5 pull requests

Successful merges:

 - #156141 (Resolve some cases of #132279 by using the right typing mode in the next solver)
 - #156244 (fix incorrect suggestions in private import diagnostic)
 - #156306 (Move tests consts)
 - #156333 (Avoid invalid spans in dotdotdot rest pattern suggestions)
 - #156337 (rustc-dev-guide subtree update)
@rust-bors rust-bors Bot merged commit 62396df into rust-lang:main May 8, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone May 8, 2026
rust-timer added a commit that referenced this pull request May 8, 2026
Rollup merge of #156244 - el-ev:issue156060, r=mu001999

fix incorrect suggestions in private import diagnostic

Resolves #156060.

1. In nested imports like `use two::{One, ...}`, the diagnostic suggested replacing the `One` with a multi-segment path of a different module, producing invalid code like `use crate::two::{one::One, Two}`. Skip it when `single_nested == true`.
2. Stop unconditionally skipping the first segment of `import.module_path`, which can produce incorrect paths in edition 2018 and later.
3. Mark the suggestion as "directly" instead of "through the re-export" when the import's source is the definition itself.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid suggestion with private import

5 participants